1、序列化二叉树
思想：利用队列
class Solution {
public:
    char* Serialize(TreeNode *root) {    
         if(root==nullptr)
             return nullptr;
        string s;
        queue<TreeNode*> q;
        q.push(root);
        while(!q.empty())
        {
            int len=q.size();
            while(len--)
            {
                TreeNode* front=q.front();
                q.pop();
                if(front)
                {
                    q.push(front->left);
                    q.push(front->right);
                    s+=to_string(front->val)+',';
                }
                else
                    s+="null,";
            }
        }
        s=s.substr(0,s.size()-1);
        char* p=new char[s.size()+1];
        strcpy(p,s.c_str());
        return p;
    }
    TreeNode* Deserialize(char *str) {
        if(str==nullptr)
            return nullptr;
        string s(str);
        string s1;
        vector<string> vs;
        for(int i=0;i<s.size();i++)
        {
            while(i<s.size()&&s[i]!=',')
                s1.push_back(s[i++]);
            vs.push_back(s1);
            s1.clear();
        }
        int index=0;
        TreeNode* head=new TreeNode(stoi(vs[index++]));
        queue<TreeNode*> q;
        q.push(head);
        while(!q.empty())
        {
            int len=q.size();
            while(len--)
            {
                TreeNode* front=q.front();
                q.pop();
                if(!front)
                    continue;
                else
                {
                    if(index<vs.size())
                    {
                        front->left=vs[index]=="null"?nullptr:new TreeNode(stoi(vs[index]));
                    }
                    index++;
                    q.push(front->left);
                    if(index<vs.size())
                    {
                        front->right=vs[index]=="null"?nullptr:new TreeNode(stoi(vs[index]));
                    }
                    index++;
                    q.push(front->right);
                }
            }
            
        }
        return head;
    }
};